home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / res / blog / selfBlog / index.php < prev    next >
PHP Script  |  2010-05-19  |  38KB  |  837 lines

  1. <?php
  2. /**
  3.  * SelfBlog main file
  4.  *
  5.  * Display, edit, modify and save blog
  6.  *
  7.  * PHP version 5
  8.  *
  9.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  10.  * that is available through the world-wide-web at the following URI:
  11.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  12.  * the PHP License and are unable to obtain it through the web, please
  13.  * send a note to license@php.net so we can mail you a copy immediately.
  14. *
  15.  * @category   NA
  16.  * @package    NA
  17.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  18.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  19.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  20.  * @version    CVS: $Id:$
  21.  * @link       http://www.weezo.net
  22.  * @since      File available since Release 1.0.0
  23.  */
  24.  
  25.  
  26. /*
  27.  * File map :
  28.  * functions    getMinMaxDate
  29.  *        generateID
  30.  *        getTimeStamp
  31.  *        getCommentsList
  32.  *        getMessagesList
  33.  *
  34.  * INIT BLOG DATA (once)
  35.  * Load messages XML file (or create it)
  36.  * PROCESS POST PARAMETERS
  37.  * Insert HEAD, FORMS and JAVASCRIPT functions
  38.  * DISPLAY BLOG
  39.  *    Messages and comments
  40.  *    Profile section
  41.  *    History
  42.  *
  43.  */
  44.  
  45. require_once(INCLUDE_DIR.'outputFunctions.php');
  46.  
  47. /**
  48.  * @return array 'min' & 'max' timestamp
  49.  * @desc return an array containing min and max timestamp of messages
  50. */
  51.  function getMinMaxDate(){
  52.      global $root;
  53.     foreach ($root->getElementsByTagName('message') as $node){
  54.         if($node->hasAttribute('ID') && $node->hasAttribute('date') && $ts=getTimeStamp($node->getAttribute('date'))){
  55.             if((!isset($min)) || $min>$ts) $min=$ts;
  56.             if((!isset($max)) || $max<$ts) $max=$ts;
  57.         }
  58.     }
  59.     if(!isset($min)) return false; else return array('min' => $min, 'max' => $max);
  60.  }
  61.  
  62. /**
  63.  * @return int ID
  64.  * @desc browse $dom for max ID found and return max ID +1 . Used to generate an unused ID for a new message or comment
  65. */
  66. function generateID(){
  67.     global $root;
  68.     $maxID=0;
  69.  
  70.     foreach ($root->getElementsByTagName('message') as $node){
  71.         if($node->hasAttribute('ID') && is_numeric($node->getAttribute('ID')) && $node->getAttribute('ID')>$maxID) $maxID=$node->getAttribute('ID');
  72.     }
  73.     foreach ($root->getElementsByTagName('comment') as $node){
  74.         if($node->hasAttribute('ID') && is_numeric($node->getAttribute('ID')) && $node->getAttribute('ID')>$maxID) $maxID=$node->getAttribute('ID');
  75.     }
  76.     return $maxID+1;
  77. }
  78.  
  79. /**
  80.  * @return long timestamp
  81.  * @param string $formated date
  82.  * @desc return time stamp from 'Y/m/d-H:i:s' formated date
  83. */
  84. function getTimeStamp($strDate){
  85.     if(strlen($strDate)!=19) return false;
  86.     return mktime(substr($strDate,11,2), substr($strDate,14,2), substr($strDate,17,2), substr($strDate,5,2), substr($strDate,8,2), substr($strDate,0,4));
  87. }
  88.  
  89. /**
  90.  * @return array : sorted array of comments, including for each comment :
  91.  *        string ID : id of comment
  92.  *        string body : body of comment
  93.  * @param domNode : $message
  94.  * @desc return an array of
  95. */
  96. function getCommentsList($messageNode){
  97.     $commentsArray=array();
  98.     $comments=$messageNode->getElementsByTagname('comment');
  99.     if($comments) foreach ($comments as $comment){
  100.         if($comment->hasAttribute('date') && $comment->hasAttribute('ID')){
  101.             // date
  102.             $timeStamp=getTimeStamp($comment->getAttribute('date'));
  103.             // ID
  104.             $commentsArray[$timeStamp]['ID']=$comment->getAttribute('ID');
  105.             // IP
  106.             if($comment->hasAttribute('IP')) $commentsArray[$timeStamp]['IP']=$comment->getAttribute('IP');
  107.             // e-mail
  108.             if($comment->hasAttribute('eMail')) $commentsArray[$timeStamp]['eMail']=$comment->getAttribute('eMail');
  109.             // web link
  110.             if($comment->hasAttribute('link')) $commentsArray[$timeStamp]['link']=$comment->getAttribute('link');
  111.             // author
  112.             $commentsArray[$timeStamp]['author']=$comment->getElementsByTagname('author')->item(0)->nodeValue;
  113.             // comment body
  114.             $commentsArray[$timeStamp]['body']=$comment->getElementsByTagname('body')->item(0)->nodeValue;
  115.             // whole comment node
  116.             $commentsArray[$timeStamp]['node']=$comment;
  117.         }
  118.     }
  119.     ksort($commentsArray);
  120.     return $commentsArray;
  121. }
  122.  
  123. /**
  124.  * @return array : array of DomElement
  125.  * @param long $dateFrom : timestamp of date from which message are included
  126.  * @param long $dateTo : timestamp of  date up to which message are included
  127.  * @desc return an array of domNodes of messages included between dateFrom and dateTo, and sort by inverse date
  128. */
  129.  function getMessagesList($dateTo=false, $dateFrom=false){
  130.      global $dom;
  131.      $messagesArray=array();
  132.      $messages=$dom->getElementsByTagName("message");
  133.     foreach ($messages as $message){
  134.         if($message->getAttribute('ID') && $message->getAttribute('date')){
  135.             if($timeStamp=getTimeStamp($message->getAttribute('date'))){
  136.                 if((!$dateTo) || (!$dateFrom && $timeStamp<=$dateTo) || ($timeStamp<=$dateTo && $timeStamp>=$dateFrom))
  137.                     $messagesArray[$timeStamp]=$message;
  138.             }
  139.         }
  140.     }
  141.     krsort($messagesArray);
  142.     return  $messagesArray;
  143.  }
  144.  
  145. /**
  146.  * @return bool : true if message found
  147.  * @param long $dateFrom : timestamp of lower bound of interval
  148.  * @param long $dateTo : timestamp of higher bound of interval
  149.  * @desc return true if a message has been posted between dateFrom and dateTo
  150. */
  151. function messageInInterval($dateTo, $dateFrom){
  152.     global $allMessages;
  153.     foreach ($allMessages as $key=>$value) if($key<=$dateTo && $key>=$dateFrom) return true;
  154.     return false;
  155.  }
  156.  
  157. /*
  158.  ***************************************************************************************************************************
  159.  * Init blog data
  160.  ***************************************************************************************************************************
  161.  */
  162. if(!cfRGetVar('parametersLoaded')){
  163.     // Set default values for unset variables (which are theoricaly present in resource config file)
  164.     if(!(cfRGetVar('commentsAllowed'))) cfRSetVar('commentsAllowed',false);
  165.     if(cfRGetVar('commentsAllowed')) cfRSetVar('displayComments',true);
  166.     if(!(cfRGetVar('maxPostPerPage'))) cfRSetVar('maxPostPerPage',5);
  167.     if(!(cfRGetVar('useProfile'))) cfRSetVar('useProfile',false);
  168.     if(!(cfRGetVar('profileName'))) cfRSetVar('profileName','');
  169.     if(!(cfRGetVar('profileEMail'))) cfRSetVar('profileEMail','');
  170.     if(!(cfRGetVar('profileComment'))) cfRSetVar('profileComment','');
  171.     if(!(cfRGetVar('userTempDirAccessAllowed'))) cfRSetVar('userTempDirAccessAllowed',false);
  172.     if(!(cfRGetVar('resourceDataDirAccessAllowed'))) cfRSetVar('resourceDataDirAccessAllowed',true);
  173.     cfRSetVar('fileTypeFilter',array('image')); // Set uploaded files extension filter
  174.     if(cfRGetVar('unfoldPosts')===false) cfRSetVar('unfoldPosts',true);
  175.     if(!isset($criticalErrorMessage)) cfRSetVar('parametersLoaded',true);
  176. }
  177. $dom = new DOMDocument('1.0', 'utf-8');
  178.  
  179. // Init / set dates
  180. if(!cfRGetVar('dateFrom')) cfRSetVar('dateFrom', false);
  181. if(!cfRGetVar('dateTo')) cfRSetVar('dateTo', mktime());
  182. $dateFrom=cfRGetVar('dateFrom');
  183. $dateTo=cfRGetVar('dateTo');
  184.  
  185. // Load XML messages file
  186. if(file_exists(cfAppResourceDir().'/blogMessages.xml')){
  187.     ;
  188.     if(!(@$dom->load(cfAppResourceDir().'/blogMessages.xml'))) {
  189.         $criticalErrorMessage=cfCaption('blogErrorFileIncorrect');
  190.         cfLog('Error : blog message file "'.cfAppResourceDir().'/blogMessages.xml'.'" couldn\'t be parsed',LOG_ER);
  191.     }
  192.     else $root=$dom->documentElement;
  193. }
  194. // If XML messages file doesn't exist, create it
  195. else{
  196.     $dom->loadXML('<?xml version="1.0" encoding="UTF-8"?><blog/>');
  197.     if(!($dom->save(cfAppResourceDir().'/blogMessages.xml'))){
  198.         $criticalErrorMessage=cfCaption('blogErrorCannotSaveFile');
  199.         cfLog('Error : blog message file "'.cfAppResourceDir().'/blogMessages.xml'.'" couldn\'t be created',LOG_ER);
  200.     }
  201.     $root=$dom->documentElement;
  202. }
  203. /*
  204.  ***************************************************************************************************************************
  205.  * Process POST commands
  206.  ***************************************************************************************************************************
  207.  */
  208. if(!isset($criticalErrorMessage)){
  209.     // Process hide / show all posts
  210.     cfAsyncXMLChangePhpVarValue('unfoldPosts');
  211.     // Change comments hide / show value from async request
  212.     cfAsyncXMLChangePhpVarValue('displayComments');
  213.  
  214.  
  215.     $saveXMLFileRequired=false;
  216.     // New message
  217.     if(isset($_POST['newMessageBody']) && cfUGetVar('administrator')){
  218.         // Generate and Append new node
  219.         $newMessageNode=$dom->createElement('message');
  220.         $newMessageNode->setAttribute('ID', generateID());
  221.         $newMessageNode->setAttribute('date', date('Y/m/d-H:i:s'));
  222.         // Message title
  223.         if(isset($_POST['newMessageTitle'])) {
  224.             $newMessageNode->appendChild($dom->createElement('title',cfXMLEncode(cfUTF8Decode($_POST['newMessageTitle'],false,true,true,64))));
  225.         }
  226.         // Image
  227.         if(cfRGetVar('uploadedImage') && cfRGetVar('uploadedImagePosition')){
  228.             if(file_exists(cfAppResourceDir().'/tmpImg.jpg')){
  229.                 $i=0;
  230.                 while (file_exists(cfAppResourceDir().'/'.$i.'.jpg')) $i++;
  231.                 rename(cfAppResourceDir().'/tmpImg.jpg', cfAppResourceDir().'/'.$i.'.jpg');
  232.                 $imageNode=$dom->createElement('image');
  233.                 $imageNode->setAttribute('fileName', $i.'.jpg');
  234.                 $imageNode->setAttribute('position', cfRGetVar('uploadedImagePosition'));
  235.                 $newMessageNode->appendChild($imageNode);
  236.             }
  237.         }
  238.         // Message body
  239.         $_POST['newMessageBody']=str_replace("\r",'<br />',str_replace("\n",'<br />',str_replace("\r\n",'<br />',$_POST['newMessageBody'])));
  240.         $newMessageNode->appendChild($dom->createElement('body',cfXMLEncode(cfUTF8Decode($_POST['newMessageBody'],false,true,false,4096))));
  241.         // set position on new message
  242.         $dateTo=getTimeStamp($newMessageNode->getAttribute('date'));
  243.         $dateFrom=false;
  244.         $saveXMLFileRequired=true;
  245.         $root->appendChild($newMessageNode);
  246.     }
  247.     // Commands sent via action / value form (edit, delete / next / previous /...)
  248.     if(isset($_POST['action']) && isset($_POST['value'])){
  249.         // Delete message or comment
  250.         if($_POST['action']=='delete' && cfUGetVar('administrator')){
  251.             // Browse comments
  252.             foreach ($root->getElementsByTagName('comment') as $node){
  253.                 if($node->getAttribute('ID')==$_POST['value']){
  254.                     $node->parentNode->removeChild($node);
  255.                     $saveXMLFileRequired=true;
  256.                     break;
  257.                 }
  258.             }
  259.             // Browse messages to find the one with matching Id
  260.             foreach ($root->getElementsByTagName('message') as $node){
  261.                 if($node->getAttribute('ID')==$_POST['value']){
  262.                     // remove image from disk
  263.                     if($node->getElementsByTagName('image')->length>0)
  264.                         @unlink(cfAppResourceDir().'/'.$node->getElementsByTagName('image')->item(0)->getAttribute('fileName'));
  265.                     $node->parentNode->removeChild($node);
  266.                     $saveXMLFileRequired=true;
  267.                     break;
  268.                 }
  269.             }
  270.         }
  271.         // Delete message or comment
  272.         elseif($_POST['action']=='edit' && cfUGetVar('administrator')){
  273.             // Browse messages to find the one with matching Id
  274.             foreach ($root->getElementsByTagName('message') as $node){
  275.                 if($node->getAttribute('ID')==$_POST['value']){
  276.                     $_POST['value2']=str_replace("\r",'<br />',str_replace("\n",'<br />',str_replace("\r\n",'<br />',$_POST['value2'])));
  277.                     // Edit date
  278.                     if($node->hasAttribute('editDate')) $node->removeAttribute('editDate');
  279.                     $node->setAttribute('editDate', time());
  280.                     // Set new title
  281.                     foreach ($node->childNodes as $subNode) if($subNode->nodeName=='title') $subNode->nodeValue=cfXMLEncode(cfUTF8Decode($_POST['value3'],false,true,false,4096));
  282.                     // Set new body
  283.                     foreach ($node->childNodes as $subNode) if($subNode->nodeName=='body') $subNode->nodeValue=cfXMLEncode(cfUTF8Decode($_POST['value2'],false,true,false,4096));
  284.                     $saveXMLFileRequired=true;
  285.                     break;
  286.                 }
  287.             }
  288.         }
  289.  
  290.         // show previous / next messages
  291.         elseif($_POST['action']=='prevNext' && is_numeric($_POST['value'])){
  292.             $dateFrom=false;
  293.             $dateTo=$_POST['value'];
  294.         }
  295.  
  296.         // show messages included in given period
  297.         if($_POST['action']=='period' && isset($_POST['value2']) && is_numeric($_POST['value'])&& is_numeric($_POST['value2'])){
  298.             $dateFrom=$_POST['value'];
  299.             $dateTo=$_POST['value2'];
  300.         }
  301.         // show messages included in given period
  302.         if($_POST['action']=='resetDate'){
  303.             $dateFrom=false;
  304.             $dateTo=mktime();
  305.         }
  306.     }
  307.  
  308.     // New comment
  309.     if(isset($_POST['newCommentAuthor']) && isset($_POST['newCommentBody']) && isset($_POST['messageID']) && cfRGetVar('commentsAllowed')){
  310.         foreach (getMessagesList(false,false) as $node){
  311.             if($node->getAttribute('ID')==$_POST['messageID']) {
  312.                 $newCommentNode=$dom->createElement('comment');
  313.                 $newCommentNode->setAttribute('ID', generateID());
  314.                 $newCommentNode->setAttribute('date', date('Y/m/d-H:i:s'));
  315.                 $newCommentNode->setAttribute('IP', $_SESSION['accountIP']);
  316.                 if(isset($_POST['newCommentEMail'])) $newCommentNode->setAttribute('eMail', cfXMLEncode(cfUTF8Decode($_POST['newCommentEMail'],false,true,true,64)));
  317.                 if(isset($_POST['newCommentLink'])) $newCommentNode->setAttribute('link', cfXMLEncode(cfUTF8Decode($_POST['newCommentLink'],false,true,true,64)));
  318.                 // Author
  319.                 $newCommentNode->appendChild($dom->createElement('author',cfXMLEncode(cfUTF8Decode($_POST['newCommentAuthor'],false,true,true,64))));
  320.                 // Comment body
  321.                 $newCommentNode->appendChild($dom->createElement('body',cfXMLEncode(cfUTF8Decode($_POST['newCommentBody'],false,true,true,2048))));
  322.                 // Append to message node
  323.                 $node->appendChild($newCommentNode);
  324.                 $saveXMLFileRequired=true;
  325.             }
  326.         }
  327.     }
  328.  
  329.     //Save XML file
  330.     if($saveXMLFileRequired && !($dom->save(cfAppResourceDir().'/blogMessages.xml'))){
  331.         $criticalErrorMessage=cfCaption('blogErrorCannotSaveFile');
  332.         cfLog('Error : blog message file "'.cfAppResourceDir().'/blogMessages.xml'.'" couldn\'t be created',LOG_ER);
  333.     }
  334.  
  335.     // Memorize position
  336.     cfRSetVar('dateFrom',$dateFrom);
  337.     cfRSetVar('dateTo', $dateTo);
  338. }
  339.  
  340.  
  341. /**
  342.  * Mobiles
  343.  */
  344. if(cfIsMobile()) {require(dirname($_SERVER['SCRIPT_FILENAME']).'/mobileIndex.php');exit;}
  345.  
  346.  
  347. /*
  348.  ***************************************************************************************************************************
  349.  * Insert HEAD, FORMS and JAVASCRIPT functions
  350.  ***************************************************************************************************************************
  351.  */
  352. if(isset($criticalErrorMessage)) outDisplayErrorPage($criticalErrorMessage); // If a critical error has been raised, display error page and exit
  353. // Get message list
  354. $messages=getMessagesList($dateTo, $dateFrom);
  355.  
  356. if(count($messages))  $minMax=getMinMaxDate(); else $minMax=false; // get date (timestamp) of 1st and last message
  357.  
  358. cfInsertHEAD(false);
  359. ?>
  360. <script language="javascript" type="text/javascript">
  361. var uploadInProgress;
  362. var commentsDisplay=<?php if(cfRGetVar('displayComments')) echo '1'; else echo '0';?>;
  363. function showNewMsg(){
  364.     dgi("newPostForm").style.display="block";
  365.     dgi("newPostButton").style.display="none";
  366. }
  367. function hideNewMsg(){
  368.     dgi("newPostForm").style.display="none";
  369.     dgi("newPostButton").style.display="block";
  370. }
  371. function sendNewMessage(){
  372.     if(uploadInProgress) alert('<?echo cfCaptionJS('genSendInProgress')."'+String.fromCharCode(13)+'".cfCaptionJS('genWait');?>');
  373.     else {
  374.         dgi('uploadResult').innerHTML='<?php echo cfCaption('genWait');?>';
  375.         if(W.winUseWindows && D.newMessage.target=="") winMe.setReloading();
  376.         D.newMessage.submit();
  377.     }
  378. }
  379. function uploadCompleted(result){
  380.     if(result) dgi('uploadResult').innerHTML='<?php echo cfCaption('blogImageSent');?>';
  381.     else dgi('uploadResult').innerHTML='<?php echo cfCaption('blogNoImageSent');?>';
  382.     uploadInProgress=false;
  383. }
  384. function deleteMsg(id){
  385.     if(confirm("<?php echo cfCaption('blogConfirmDelete');?>")){
  386.         dgi("action").value='delete';
  387.         dgi("value").value=id;
  388.         if(W.winUseWindows && document.forms.miscAction.target=="") winMe.setReloading();
  389.         document.forms['miscAction'].submit();
  390.     }
  391. }
  392. function saveEditMsg(id){
  393.     dgi("action").value='edit';
  394.     dgi("value").value=id;
  395.     dgi("value2").value=dgi("messageEdit"+id).value;
  396.     dgi("value3").value=dgi("messageEditTitle"+id).value;
  397.     if(window.winUseWindows && document.forms.miscAction.target=="") winMe.setReloading();
  398.     document.forms['miscAction'].submit();
  399. }
  400. function editMsg(id,focus){
  401.     if(dgi("messageEdit"+id)) return;
  402.     //Bt
  403.     dgi("supprBt"+id).style.display="none";
  404.     dgi("saveBt"+id).style.display="inline";
  405.     // Body
  406.     var h=dgi("message"+id).offsetHeight;
  407.     var ih=dgi("message"+id).innerHTML.replace(/<BR\/>/gi,String.fromCharCode(13)).replace(/<BR>/gi,String.fromCharCode(13));
  408.     dgi("message"+id).innerHTML='<textarea style="width:100%;" rows="5" id="messageEdit'+id+'">'+ih+'</textarea>';
  409.     while(dgi("messageEdit"+id).offsetHeight<h && dgi("messageEdit"+id).rows<15) dgi("messageEdit"+id).rows++;
  410.     // Title
  411.     h=dgi("messageT"+id).offsetWidth;
  412.     ih=dgi("messageT"+id).innerHTML;
  413.     dgi("messageT"+id).innerHTML='<input class="textInput" style="vertical-align:middle" id="messageEditTitle'+id+'">';
  414.     dgi("messageEditTitle"+id).value=ih;
  415.     var w=100;
  416.     while(dgi("messageEditTitle"+id).offsetWidth<h) {w+=5;dgi("messageEditTitle"+id).style.width=w+"px";}
  417.     if(!focus) dgi("messageEditTitle"+id).focus(); else dgi("messageEdit"+id).focus();
  418. }
  419. function goMsg(ts){
  420.     dgi("action").value='prevNext';
  421.     dgi("value").value=ts;
  422.     if(window.winUseWindows && document.forms.miscAction.target=="") winMe.setReloading();
  423.     document.forms['miscAction'].submit();
  424. }
  425. function goMsgs(sts,ets){
  426.     dgi("action").value='period';
  427.     dgi("value").value=sts;
  428.     dgi("value2").value=ets;
  429.     if(window.winUseWindows && document.forms.miscAction.target=="") winMe.setReloading();
  430.     document.forms['miscAction'].submit();
  431. }
  432. function resetDate(){
  433.     dgi("action").value='resetDate';
  434.     if(window.winUseWindows && document.forms.miscAction.target=="") winMe.setReloading();
  435.     document.forms['miscAction'].submit();
  436. }
  437. function sendComment(id){
  438.     if(document.forms['newComment'+id].newCommentAuthor.value.length==0 || document.forms['newComment'+id].newCommentBody.value.length==0 )
  439.         alert('<? echo cfCaptionJS('genFillFields');?>');
  440.     else
  441.     {
  442.         if(window.winUseWindows && document.forms['newComment'+id].target=="") winMe.setReloading();
  443.         document.forms['newComment'+id].submit();
  444.     }
  445. }
  446. function showNewComment(id){
  447.     dgi('comment'+id).align="left";
  448.     var ih='<form name="newComment'+id+'" method="post" enctype="multipart/form-data">';
  449.     ih+='<div style="padding-bottom:0.5em;"><?php  echo cfCaption('genAuthor','');?><input class="textInput" type="text" name="newCommentAuthor" size="60" value="<?php echo htmlentities(cfUTF8Encode((cfUGetVar('pseudo'))?cfUGetVar('pseudo'):cfUGetVar('name')),ENT_QUOTES); ?>"></div>';
  450.     ih+='<div style="padding-bottom:0.5em;"><?php  echo cfCaption('genEMail');?> <input class="textInput" type="text" name="newCommentEMail" size="60"></div>';
  451.     ih+='<div style="padding-bottom:0.5em;"><?php  echo cfCaption('blogLink');?> <input class="textInput" type="text" name="newCommentLink" size="60"></div>';
  452.     ih+='<textarea cols="60" rows="5" wrap="virtual" name="newCommentBody" style="margin-bottom:0.5em;width:100%"></textarea><br/><?php
  453.     echo  outButton(cfCaption('genValidate'),'javascript:sendComment(\'+id+\')',outIcon('edit'),false,false,false,false);
  454.     echo '<input type="hidden" name="resId" value="'.$_SESSION['activeResourceId'].'">';
  455.     ?><input name="messageID" type="hidden" value="'+id+'"></form>';
  456.     dgi('comment'+id).innerHTML=ih;
  457. }
  458. function toggleCommentsDisplay(nb){
  459.     if(!nb){
  460.         if(sendData("displayComments="+(1-commentsDisplay),"<?php echo $_SERVER['PHP_SELF'];?>",false)==false) return;
  461.         var i=0;
  462.         commentsDisplay=1-commentsDisplay;
  463.         if(commentsDisplay==1) {
  464.             dgi('showCommentsBt').style.display="none";
  465.             dgi('hideCommentsBt').style.display="inline";
  466.         }
  467.         else{
  468.             dgi('showCommentsBt').style.display="inline";
  469.             dgi('hideCommentsBt').style.display="none";
  470.         }
  471.         while(dgi('commentsArea'+i)){
  472.             if(commentsDisplay==1) dgi('commentsArea'+i).style.display="inline"; else dgi('commentsArea'+i).style.display="none";
  473.             i++;
  474.         }
  475.     }
  476.     else{
  477.         if(dgi('commentsArea'+nb).style.display=="none") dgi('commentsArea'+nb).style.display="inline"; else dgi('commentsArea'+nb).style.display="none";
  478.     }
  479. }
  480. function collapseAll(){
  481.     sendData("unfoldPosts=false","<?php echo $_SERVER['PHP_SELF'];?>",false);
  482.     i=0; while(dgi('innerMsgDiv' + i)){if(!wl.isCollapsed('innerMsgDiv'+i)) wl.nodeCollapseFold('innerMsgDiv' + i,false);i++;}
  483.     dgi('unfoldAllBt').style.display="inline";
  484.     dgi('collapseAllBt').style.display="none";
  485. }
  486. function unfoldAll(){
  487.     sendData("unfoldPosts=true","<?php echo $_SERVER['PHP_SELF'];?>",false);
  488.     i=0; while(dgi('innerMsgDiv' + i)){if(wl.isCollapsed('innerMsgDiv'+i)) wl.nodeCollapseUnfold('innerMsgDiv' + i,false);i++;}
  489.     dgi('unfoldAllBt').style.display="none";
  490.     dgi('collapseAllBt').style.display="inline";
  491. }
  492. </script>
  493. </head>
  494. <form name="miscAction" action="index.php" enctype="multipart/form-data" method="POST" style="display:none;">
  495. <input name="action" id="action" type="hidden">
  496. <input name="value" id="value" type="hidden">
  497. <input name="value2" id="value2" type="hidden">
  498. <input name="value3" id="value3" type="hidden">
  499. <input type="hidden" name="resId" value="<?php echo $_SESSION['activeResourceId']; ?>">
  500. </form>
  501. <?php
  502.  
  503.  
  504. /*
  505.  ***************************************************************************************************************************
  506.  * Display BLOG
  507.  ***************************************************************************************************************************
  508.  */
  509.  
  510. // if a non critical error message is present, display it in a javascript alert box
  511. if(isset($errorMessage)) echo"<body onload=\"javascript:alert('".$errorMessage."');\">";
  512. else echo "\n<body>\n";
  513.  
  514. /*
  515.  * Messages and comments Section
  516. */
  517.  
  518. $allMessages=getMessagesList(false,false); // Get an array with all blog's messages. This array is used for previous/next buttons and for history
  519.  
  520. echo '<div id="topDiv">';
  521. echo '<table width="100%"><tr>';
  522. echo '<td id="mainTable" style="vertical-align:top;" width="'.((cfIsWII())?'100%':'80%').'">';
  523. outShadowBefore('100%');
  524. echo outDivFrame('frame1');
  525.  
  526. // Toggle comments display button
  527. $tmpButton='';
  528. $tmpButton.=outButton('', 'javascript:unfoldAll(false)',outIcon('plusX2'),false,'unfoldAllBt',((cfRGetVar('unfoldPosts'))?'style="display:none"':''));
  529. $tmpButton.=outButton('', 'javascript:collapseAll(false)',outIcon('minusX2'),false,'collapseAllBt',((cfRGetVar('unfoldPosts'))? '': 'style="display:none"'));
  530. if(cfRGetVar('commentsAllowed')) {
  531.     $tmpButton.=outButton(cfcaption('blogCommentsShow'), 'javascript:toggleCommentsDisplay(false)',false,false,'showCommentsBt',((cfRGetVar('displayComments'))? 'style="display:none"':''),false);
  532.     $tmpButton.=outButton(cfcaption('blogCommentsHide'), 'javascript:toggleCommentsDisplay(false)',false,false,'hideCommentsBt',((cfRGetVar('displayComments'))? '': 'style="display:none"'),false);
  533. }
  534. else $tmpButton=false;
  535.  
  536. // Frame1Header
  537. echo outFrameHeaderTable('frame1Header',cfUTF8Encode(cfRGetVar('name')),$tmpButton);
  538. echo '<div style="position:relative; width:400px;height:0px;"></div>'; // = min-width...
  539.  
  540. if($minMax || cfUGetVar('administrator')){
  541.     $tableDisplayed=false;
  542.  
  543.     // New message button & form
  544.     if(cfUGetVar('administrator')){
  545.         echo outTableTransparent('frame1',"margin-bottom:0.5em;").'<tr><td style="text-align:left" width="50%">';
  546.         $tableDisplayed=true;
  547.         // "Post new message" button
  548.         echo '<span id="newPostButton">'.outButton(cfCaption('blogPostNewMessage'),'javascript:showNewMsg()',outicon('edit')).'</span>';
  549.         echo '</td>';
  550.     }
  551.     // "Next messages" button
  552.     if($minMax){
  553.         reset($messages); // position on first (most recent) of displayed messages
  554.         if(getTimeStamp(current($messages)->getAttribute('date'))<$minMax['max']){ // If this message is not the most recent
  555.             if(!$tableDisplayed){
  556.                 echo outTableTransparent('frame1',"margin-bottom:0.5em;").'<tr>';
  557.                 $tableDisplayed=true;
  558.             }
  559.             echo '<td style="text-align:right">';
  560.             // Find this message in entire messages list.
  561.             reset($allMessages); for($i=0;$i<count($allMessages);$i++) {if(current($allMessages)->getAttribute('date')==current($messages)->getAttribute('date')) break; next($allMessages);}
  562.             // Move maxPostPerPage steps backward
  563.              for($i=0;$i<cfRGetVar('maxPostPerPage');$i++) @prev($allMessages); if(!current($allMessages)) reset($allMessages);
  564.              $nextTS=getTimeStamp(current($allMessages)->getAttribute('date'));
  565.             // Display button
  566.             echo '<span style="width:50%;text-align:right;">'.outButton(cfCaption('blogNextPosts'),'javascript:goMsg('.$nextTS.')',outIcon('up'),cfCaption('blogNextPosts')).'</span></td>';
  567.         }
  568.     }
  569.     if($tableDisplayed) echo "</tr></table>\n";
  570.  
  571.     // New message form
  572.     if(cfUGetVar('administrator')){
  573.         echo '<span id="newPostForm" style="display:none;" class="frame2"><div class="frame2Header"><img alt="" src="'.outIcon('edit').'" style="vertical-align:middle; margin-right:1em;">'.cfCaption('blogPostNewMessage').'</div>';
  574.  
  575.  
  576.  
  577.         echo '<form name="newMessage" method="post" enctype="multipart/form-data">';
  578.         // Title
  579.         echo '<div style="padding-bottom:0.5em;">'.cfCaption('genTitle').'  <input class="textInput" type="text" name="newMessageTitle" size="80"></div>';
  580.         // Textarea
  581.         echo '<textarea cols="80" rows="7" name="newMessageBody" style="width:100%"></textarea>';
  582.         // resId
  583.         echo '<input type="hidden" name="resId" value="'.$_SESSION['activeResourceId'].'">';
  584.         echo '</form>';
  585.  
  586.  
  587.  
  588.         // Insert image form
  589.         echo '<div class="frame3"><div class="frame3header">'.cfCaption('blogInsertImage').'</div>';
  590.  
  591.  
  592.         // Position of image in message
  593.         $extraInnerHTML=cfCaption('genPosition').'  <input type="radio" name="position" value="top" checked><img src="imgTop.gif">';
  594.         $extraInnerHTML.='<input type="radio" name="position" value="bottom"><img src="imgBottom.gif"/>';
  595.         // Size of image in message
  596.         $extraInnerHTML.='<span style="padding-left:3em;padding-right:2em;">'.cfCaption('genSize').'<input type="radio" name="size" value="small" checked /><img src="'.outIcon('imgSmall').'" alt=""><input type="radio" name="size" value="medium" checked /><img src="'.outIcon('imgMedium').'"><input type="radio" name="size" value="big" /><img src="'.outIcon('imgBig').'"></span><br/>';
  597.  
  598.         // Insert upload form
  599.         outUploadForm('40','uploadCompleted','none','*resourceDataDir*',$extraInnerHTML);
  600.         echo '<center>'.outButton(cfCaption('genSend'),'javascript:initUpload();',outIcon('ok'),false,'uploadFormSubmitButton')."</center>\n";
  601.  
  602.         // Upload result message
  603.         echo'<div class="frame3Footer" id="uploadResult">'.cfCaption('blogNoImageSent').'</div></div>';
  604.  
  605.         // Validate
  606.         echo '<br/><center>'.outButton(cfCaption('genValidate'),'javascript:sendNewMessage()',outIcon('edit'));
  607.         // Cancel
  608.         echo '<span style="margin-left:10em;"></span>'.outButton(cfCaption('genCancel'),'javascript:hideNewMsg()',outIcon('cancel')).'</center>';
  609.     echo '</span>';
  610.     }
  611. }
  612.  
  613.  
  614. /*
  615.  ***************************************************************************************************************************
  616.  * Messages and comments
  617.  ***************************************************************************************************************************
  618.  */
  619. $nbDisplayedMessages=0;
  620. $nbCommentFrames=0;
  621. $currentCommentFrames=-1;
  622. if(!count($messages)) echo '<br/><br/><center>'.cfCaption('blogNoPost').'</center><br/><br/><br/>';
  623. else foreach ($messages as $message){
  624.     if(cfRGetVar('maxPostPerPage') && cfRGetVar('maxPostPerPage') <= $nbDisplayedMessages) break; // Limit number of displayed messages
  625.     /*
  626.      * MESSAGE
  627.      */
  628.  
  629.     // Message frame
  630.     echo outDivFrame('frame2');
  631.     // Delete message button
  632.     if(cfUGetVar('administrator')) {
  633.         $tmpLeft=outButton('','javascript:deleteMsg('.$message->getAttribute('ID').')',outIcon('cancel'),cfCaption('genDelete'),'supprBt'.$message->getAttribute('ID'),'style="margin-right:3px;"');
  634.         $tmpLeft.=outButton('','javascript:saveEditMsg('.$message->getAttribute('ID').')',outIcon('save'),cfCaption('genSave'),'saveBt'.$message->getAttribute('ID'),'style="margin-right:3px;display:none"');
  635.         $tmpLeft.='<span id="messageT'.$message->getAttribute('ID').'" onclick="javascript:editMsg('.$message->getAttribute('ID').',0)" style="cursor:pointer">';
  636.     }
  637.     else $tmpLeft=' ';
  638.     // Message title
  639.     $tmpLeft.=($message->getElementsByTagname('title')->item(0)->nodeValue);
  640.     if(cfUGetVar('administrator')) $tmpLeft.='</span>';
  641.  
  642.     // Message collapse button
  643.     $tmpRight=outButtonToggleCollapse('innerMsgDiv'.$nbDisplayedMessages,false,cfRGetVar('unfoldPosts'));
  644.  
  645.     echo outFrameHeaderTable('frame2Header',$tmpLeft, $tmpRight);
  646.  
  647.     // Collapsing post frame
  648.     echo outCollapsableFrame('innerMsgDiv'.$nbDisplayedMessages,'unfoldPosts');
  649.  
  650.     // Top image
  651.     $body=$message->getElementsByTagname('body')->item(0);
  652.     $image=$message->getElementsByTagname('image');
  653.     if($image->length && $image->item(0)->hasAttribute('position') && $image->item(0)->hasAttribute('fileName') && $image->item(0)->getAttribute('position')=='top') echo '<center>'.outImage(cfAppResourceDir().'/'.$image->item(0)->getAttribute('fileName')).'</center>';
  654.     // Message body
  655.     if(cfUGetVar('administrator'))
  656.         echo '<span id="message'.$message->getAttribute('ID').'" onclick="javascript:editMsg('.$message->getAttribute('ID').',1)" style="cursor:pointer; width:99%; position:relative">'.$body->nodeValue.'</span>';
  657.     else
  658.         echo '<span id="message'.$message->getAttribute('ID').'" style="width:99%; position:relative">'.$body->nodeValue.'</span>';
  659.     // Bottom image
  660.     if($image->length && $image->item(0)->hasAttribute('position') && $image->item(0)->hasAttribute('fileName') && $image->item(0)->getAttribute('position')=='bottom') echo '<center>'.outImage(cfAppResourceDir().'/'.$image->item(0)->getAttribute('fileName')).'</center>';
  661.     echo '<br/><br/>';
  662.  
  663.  
  664.     /*
  665.      * COMMENTS
  666.      */
  667.     if(cfRGetVar('commentsAllowed')){
  668.         // Comment div, hidden or shown by toggleCommentsDisplay script
  669.         echo outCollapsableFrame('commentsArea'.$nbCommentFrames,'displayComments');
  670.         $currentCommentFrames=$nbCommentFrames;    $nbCommentFrames++;
  671.         foreach (getCommentsList($message) as $ts=>$comment){
  672.             echo '<div class="frame3">';
  673.             // Comment header
  674.             echo '<div class="frame3header">'.cfCaption('blogCommentTitle',$comment['author']);
  675.             if(isset($comment['eMail']) || isset($comment['link']) || cfUGetVar('administrator')) {
  676.                 echo ' (';
  677.                 if(isset($comment['eMail'])) echo outMailSafe($comment['eMail']);
  678.                 if(isset($comment['link'])) {
  679.                     if(strtolower(substr($comment['link'],0,4))!='http') $link='http://'.$comment['link']; else $link=$comment['link'];
  680.                     echo ((isset($comment['eMail'])?' / ':'').'<a href="'.$link.'" target="_blank">'.cfUTF8Encode($comment['link']).'</a>');
  681.                 }
  682.                 if(isset($comment['IP']) && cfUGetVar('administrator')) echo (isset($comment['eMail']) || isset($comment['link'])?' / ':'').'<a href="http://'.$comment['IP'].'" target="_blank">'.$comment['IP'].'</a>';
  683.                 echo ')';
  684.             }
  685.             echo "</div>\n";
  686.             // Comment body
  687.             echo $comment['body'];
  688.             // Delete comment button
  689.             if(cfUGetVar('administrator'))
  690.                 echo '<div align="right">'.outButton(cfCaption('genDelete'),'javascript:deleteMsg('.$comment['ID'].')',outIcon('cancel')).'</div>';
  691.             echo '<div class="frame3Footer">'.cfUTF8Encode(date(cfCaption('blogPostedDateFormat'), $ts)).'</div>';
  692.             echo '</div><br/>';
  693.         }
  694.         echo '</div>';
  695.     }
  696.         // Add comment button
  697.         if(cfRGetVar('commentsAllowed')) {
  698.             $tempRight=outButton(cfCaption('blogAddComment'),'javascript:showNewComment('.$message->getAttribute('ID').')','balloon.png');
  699.             echo '<span id="comment'.$message->getAttribute('ID').'"></span>';
  700.         }
  701.         else $tempRight=' ';
  702.  
  703.     // Message footer
  704.     // Message date
  705.     $tempLeft=cfCaption('blogPosted',cfUTF8Encode(date(cfCaption('blogPostedDateFormat'), getTimeStamp($message->getAttribute('date')))));
  706.     if($message->hasAttribute('editDate')) $tempLeft.=', '.cfCaption('blogEdited',cfUTF8Encode(date(cfCaption('blogPostedDateFormat'), ($message->getAttribute('editDate')))));
  707.     if(cfRGetVar('commentsAllowed')){
  708.         // Number of comments
  709.         if($currentCommentFrames!=-1 && count(getCommentsList($message))) $tempLeft.= '<a href="javascript:toggleCommentsDisplay('.$currentCommentFrames.')" style="margin-left:3em;text-decoration:underline">'.((cfRGetVar('commentsAllowed'))?cfCaption('blogComments',count(getCommentsList($message))):'').'</a>';
  710.         else $tempLeft.= '<span style="margin-left:3em">'.((cfRGetVar('commentsAllowed'))?cfCaption('blogComments',count(getCommentsList($message))):'').'</span>';
  711.         $currentCommentFrames=-1;
  712.     }
  713.     // Display footer
  714.     echo outFrameFooterTable('frame2footer', $tempLeft, $tempRight);
  715.  
  716.     echo "</div></div>\n";
  717.     $nbDisplayedMessages++;
  718. }
  719.  
  720.  
  721. // "Previous messages" button
  722. if($minMax){
  723.     reset($messages); for($i=1;$i<cfRGetVar('maxPostPerPage');$i++) @next($messages); // Position on last (oldest) message
  724.     if(!current($messages)) end($messages); // If $messages contains less than maxPostPerPage, go to last message
  725.  
  726.     if(getTimeStamp(current($messages)->getAttribute('date'))>$minMax['min']){ // If this message is not the most recent
  727.         // Find this message in entire messages list.
  728.         reset($allMessages);
  729.         for($i=0;$i<count($allMessages);$i++) {
  730.             if(current($allMessages)->getAttribute('date')==current($messages)->getAttribute('date')) break;
  731.             next($allMessages);
  732.         }
  733.         @next($allMessages); // Move one step forward
  734.         $previousTS=getTimeStamp(current($allMessages)->getAttribute('date'));
  735.         // Display button
  736.         echo '<div align="right">'.outButton(cfCaption('blogPreviousPosts'),'javascript:goMsg('.$previousTS.')',outIcon('down'),cfCaption('blogPreviousPosts')).'</div>';
  737.     }
  738. }
  739.  
  740. echo '</div>';
  741. outFrameShadowAfter();
  742. echo "</td>\n";
  743.  
  744.  
  745. /*
  746.  ***************************************************************************************************************************
  747.  * RIGHT FRAME
  748.  ***************************************************************************************************************************
  749.  */
  750. echo '<td id="profileTable" width="20%" '.((cfIsWII())?'style="position:absolute;width:0;overflow:hidden;vertical-align:top;"':'style="vertical-align:top;"').' class="vBanner">';
  751.  
  752. /*
  753.  * Profile Section
  754. */
  755. if(cfRGetVar('useProfile')) {
  756.     outShadowBefore('100%');
  757.     echo outDivFrame('frame1');
  758.     echo outFrameHeaderTable('frame1header',outImage('profile.png',false,false, 'margin-right:1em;vertical-align:middle'),cfCaption('blogProfile'));
  759.     if(cfRGetVar('profileName')) echo '<div class="bigFont">'.cfUTF8Encode(cfRGetVar('profileName')).'<br/><br/></div>'; // Profile name
  760.     if(cfRGetVar('profileEMail')) echo outMailSafe(cfRGetVar('profileEMail')).'<br/><br/>'; // Profile e-mail
  761.     if(cfRGetVar('profileComment')) echo '<div>'.cfUTF8Encode(cfRGetVar('profileComment')).'</div>'; // Profile comment
  762.     echo "<br></div>\n";
  763.     outFrameShadowAfter();
  764.     echo "<br/>\n";
  765. }
  766.  
  767.  
  768.  
  769. /*
  770. * History
  771. */
  772. outShadowBefore('100%');
  773. echo outDivFrame('frame1');
  774. echo outFrameHeaderTable('frame1header',outImage('calendar.png',false,false, 'margin-right:1em;vertical-align:middle'),cfCaption('blogPreviousPosts'));
  775. @setlocale(LC_TIME , cfCaption('_ISO_639'));
  776. // Display calendar of current month
  777.  
  778.  
  779.     $firstDayOfMonth=mktime(0,0,1,date('n'),1,date('Y'));
  780.     $day=$firstDayOfMonth; while (date('w',$day)!=1) $day+=3600*24;
  781.     $offset=(date('w',$firstDayOfMonth)==0)?7:date('w',$firstDayOfMonth);
  782.     echo '<center>';
  783.     // Current month
  784.     echo outButton(cfUTF8Encode(ucfirst(strftime('%B %Y',$firstDayOfMonth))),'javascript:resetDate()',false,false,false,'style="width:12em;"');
  785.     // Calendar header
  786.     echo '<table class="frame3" style="text-align:center;table-layout:fixed" cellspacing="0" cellpadding="0"><tr class="frame3header">';
  787.     for($i=0;$i<7;$i++) {echo '<td style="width:20px">'.cfUTF8Encode(strtoupper(substr(strftime('%A',$day),0,1))).'</td>'; $day+=3600*24;}
  788.     echo '</tr><tr class="bsRow">';
  789.     // Calendar body (days)
  790.     $day=$firstDayOfMonth;
  791.     for($i=1;$i<$offset;$i++) echo '<td> </td>';
  792.     $position=$offset-1;
  793.     for($i=1;$i<date('t',$firstDayOfMonth)+1;$i++){
  794.         if($position==7) {$position=0; echo '</tr><tr class="bsRow">';}
  795.         $position++;
  796.         if(messageInInterval(mktime(23,59,59,date('n',$firstDayOfMonth),$i,date('Y',$firstDayOfMonth)),mktime(0,0,1,date('n',$firstDayOfMonth),$i,date('Y',$firstDayOfMonth)))){
  797.             echo '<td class="buttonSmall" onclick="goMsgs(\''.mktime(0,0,1,date('n',$firstDayOfMonth),$i,date('Y',$firstDayOfMonth)).'\',\''.mktime(23,59,59,date('n',$firstDayOfMonth),$i,date('Y',$firstDayOfMonth)).'\')">'.$i.'</td>';
  798.         }
  799.         else echo '<td class="buttonSmallDisabled">'.$i.'</td>';
  800.     }
  801.     echo '</tr></table><br/>';
  802.  
  803.     // Older messages (previous month)
  804.     $lastDisplayedMonth=mktime(0,0,1,date('n',$firstDayOfMonth),1,date('Y',$firstDayOfMonth));
  805.     foreach ($allMessages as $key=>$value){
  806.         $currentMonth=mktime(0,0,1,date('n',$key),1,date('Y',$key));
  807.         if($currentMonth<$lastDisplayedMonth){
  808.             echo outButton(cfUTF8Encode(ucfirst(strftime('%B %Y',$currentMonth))),'javascript:goMsgs('.$currentMonth.','.mktime(23,59,59,date('n',$currentMonth),date('t',$currentMonth),date('Y',$currentMonth)).')',false,false,false,'style="width:12em;"',true).'<br>';
  809.             $lastDisplayedMonth=$currentMonth;
  810.         }
  811.     }
  812. echo '<br/></center></div>';
  813.  
  814. //messageInInterval
  815. outFrameShadowAfter();
  816. echo '</td></tr></table>';
  817. outKeysManager();
  818. ?>
  819. <script type="text/javascript">
  820. var profileTableShown=false;
  821. function optionKeyPressed(){
  822.     if(!profileTableShown) {
  823.         dgi("profileTable").style.position="relative";
  824.         dgi("mainTable").style.display="none";
  825.         profileTableShown=true;
  826.     }
  827.     else {
  828.         dgi("profileTable").style.position="absolute";
  829.         dgi("mainTable").style.display="inline";
  830.         profileTableShown=false;
  831.     }
  832. }
  833. <?php if(cfIsWII()) echo 'winMe.addIcon("option",optionKeyPressed,"'.outIcon('winOpt').'", "'.cfCaption('genOptions').'");'; ?>
  834. </script>
  835. </div>
  836. </body>
  837. </html>